﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
//using System.Data.OracleClient;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using Oracle.ManagedDataAccess.Client;
using System.Xml;
using System.Drawing;

// 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、服务和配置文件中的类名“Service”。
public class Service : IService
{

    private string ConnectionString = ConfigurationManager.AppSettings["DBLink"];
    private Dbcom cm = new Dbcom();

    #region 测试
    public string GetData(int value,Class_Patients tp,Class_Template template, Class_Datacodecs dbcode)
	{              
        return string.Format("You entered: {0}", value);
	}

    public string GetName(string val)
    {
        return val + "123456";
    }

    public CompositeType GetDataUsingDataContract(CompositeType composite)
    {
        if (composite == null)
        {
            throw new ArgumentNullException("composite");
        }
        if (composite.BoolValue)
        {
            composite.StringValue += "Suffix";
        }
        return composite;
    }
    #endregion

    #region 数据库操作
    public DataSet GetDataSet(string CmdString)
    {
      
       return Dbcom.GetDataSet(CmdString);
    }


    public DataSet GetDataSets(Class_Table[] tabsqls)
    {        
        return Dbcom.GetDataSets(tabsqls);
    }

    public string ReadSqlVal(string CmdString, int rowindex, string colName)
    {       
        return Dbcom.ReadSqlVal(CmdString, rowindex, colName);
    }

    public int ExecuteSQL(string CmdString)
    {       
        return Dbcom.ExecuteSQL(CmdString);
    }


    public int ExecuteBatch(string[] BatchSql)
    {      
        return Dbcom.ExecuteBatch(BatchSql);
    }

    /// <summary>
    /// 以带参数的形式执行操作
    /// </summary>
    /// <param name="CmdString">SQL语句</param>
    /// <param name="Parameters">参数集合</param>       
    /// <returns></returns>
    public int ExecuteSQLWithParams(string CmdString, DBParameter[] paremts)
    {       
        return Dbcom.ExecuteSQLWithParams(CmdString, paremts);
    }

    #endregion

    #region 文书操作
    public string GetXmlDocs(string textid, string patientid, string Doctype, string NewDocXml)
    {
        DocOperation docop = new DocOperation(cm);
        return docop.GetXmlDocs(textid,patientid,Doctype,NewDocXml);
    }
  
    #endregion

    #region 文书树/类型操作
    public List<UcTreeNode> GetAllText()
    {       
        TextOperation textop = new TextOperation(cm);      
        return textop.GetAllText();
    }

    public UcTreeNode ReflashBookTree(InPatientInfo inpo)
    {
        TextOperation textop = new TextOperation(cm);
        return textop.ReflashBookTree(inpo);
    }

    /// <summary>
    /// 获取所有的已写文书
    /// </summary>
    /// <param name="Id"></param>
    /// <returns></returns>
    public UcTreeNode GetFinishNode(string Id)
    {
        DocOperation Docop = new DocOperation(cm);
        return Docop.GetFinishNode(Id);
    }


    public Class_Text[] GetSelectClassDs(DataSet tempds)
    {
        TextOperation textop = new TextOperation(cm);
        return textop.GetSelectClassDs(tempds);
    }


    /// <summary>
    /// 返回服务器时间
    /// </summary>
    /// <returns></returns>    
    public DateTime GetSystemTime()
    {
        return Dbcom.GetSystemTime();
    }

    /// <summary>
    /// 当前选中文书的一些信息
    /// </summary>
    /// <param name="tid"></param>
    /// <returns></returns>
    public DataSet GetCurrentDocInfo(string tid)
    {
        DocOperation tp = new DocOperation(cm);
        return tp.GetCurrentDocInfo(tid);
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="patient_id"></param>
    /// <returns></returns>
    public UcTreeNode SelectDoc(string patient_id)
    {
        DocOperation tp = new DocOperation(cm);
        return tp.SelectDoc(patient_id);
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="id"></param>
    /// <param name="tid"></param>
    /// <returns></returns>
    public UcTreeNode SelectDoc2(int id, string tid)
    {
        DocOperation tp = new DocOperation(cm);
        return tp.SelectDoc(id, tid);
    }

    public InPatient_Doc[] GetSelectNodes(string textid, string patient_id)
    {
        DocOperation tp = new DocOperation(cm);
        return tp.GetSelectNodes(textid,patient_id);
    }


    public void filterInfo(XmlElement bodyElement, InPatientInfo InpatientInfo, int TextKind_id, int Tid)
    {
        DocOperation tp = new DocOperation(cm);
        tp.filterInfo(bodyElement, InpatientInfo, TextKind_id, Tid);
    }


    public void filterInfo2(XmlElement bodyElement, int TextKind_id)
    {
        DocOperation tp = new DocOperation(cm);
        tp.filterInfo(bodyElement, TextKind_id);
    }

    public Dictionary<string, string> GetTextInfo(InPatientInfo inPatient, string textId)
    {
        DocOperation tp = new DocOperation(cm);
        return tp.GetTextInfo(inPatient,textId);
    }

    public string DocFromXmlBytText(string text_id, string patient_id)
    {
        DocOperation tp = new DocOperation(cm);
        return tp.DocFromXmlBytText(text_id, patient_id);
    }

    public InPatient_Doc GetDocbyId(string tid, string patient_id, string doctype)
    {
        DocOperation tp = new DocOperation(cm);
        return tp.GetDocbyId(tid, patient_id, doctype);
    }

    public int DeleteDocById(string nodeid, string DocType, InPatientInfo inpt, string User_id, string User_name)
    {
        DocOperation tp = new DocOperation(cm);
        return tp.DeleteDocById(nodeid, DocType, inpt, User_id, User_name);
    }


    public string isExitRecord(int id, int patient_id)
    {
        DocOperation tp = new DocOperation(cm);
        return  tp.isExitRecord(id,patient_id);
    }

    public string GetTextDocXmlById(string tid)
    {
        DocOperation tp = new DocOperation(cm);
        return tp.GetTextDocXmlById(tid);
    }

     /// <summary>
     /// 文书保存
     /// </summary>
     /// <param name="Tid"></param>
     /// <param name="TextKind_id"></param>
     /// <param name="blfalse"></param>
     /// <param name="IsMore"></param>
     /// <param name="textTitle"></param>
     /// <param name="UserAccount"></param>
     /// <param name="InpatientInfo"></param>
     /// <param name="haveSuperior"></param>
     /// <param name="havaTube"></param>
     /// <param name="Belong_ToSys_ID"></param>
     /// <param name="SickKind_ID"></param>
     /// <param name="OldTextName"></param>
     /// <param name="TextSuperiorSignature"></param>
     /// <param name="SuporSign"></param>
     /// <param name="haveD"></param>
     /// <param name="isTakeSuperiorZz"></param>
     /// <param name="isTakeSuperiorZr"></param>
     /// <param name="qualityTitle"></param>
     /// <param name="tempxmldoc"></param>
    public void SaveDoc(ref int Tid, int TextKind_id, bool blfalse, bool IsMore, string textTitle, string Role_type, string User_id,InPatientInfo InpatientInfo,
                       string haveSuperior, string havaTube, string Belong_ToSys_ID, string SickKind_ID, string OldTextName,
                       string TextSuperiorSignature, string SuporSign, bool haveD, bool isTakeSuperiorZz, bool isTakeSuperiorZr,
                       string qualityTitle, string tempxmldocstr)
    {
        DocOperation tp = new DocOperation(cm);
        tp.SaveDoc(ref Tid, TextKind_id, blfalse, IsMore, textTitle,Role_type, User_id,
                        InpatientInfo,
                       haveSuperior, havaTube, Belong_ToSys_ID, SickKind_ID, OldTextName,
                       TextSuperiorSignature, SuporSign, haveD, isTakeSuperiorZz, isTakeSuperiorZr,
                       qualityTitle,  tempxmldocstr);
    }

    public Class_Text GetTextClsById(string id)
    {
        TextOperation tp = new TextOperation(cm);
        return tp.GetTextClsById(id);
    }

    public Class_Text[] GetClassTestDsByName(string textname)
    {
        TextOperation tp = new TextOperation(cm);
        return tp.GetClassTestDsByName(textname);
    }

    public int ChangeTextShowNum(string shownum1, string id1, string shownum2, string id2)
    {
        TextOperation tp = new TextOperation(cm);
        return tp.ChangeTextShowNum(shownum1, id1, shownum2, id2);
    }

    public int InsertText(string txtName, string txtNumber, string cboEditorSelectIndex, string fahterId,
                            string cboBookAttributeSelectedIndex, string mark, string sid, string signatrue, string cboTimeTitle,
                            string fromname, string cboDoctorOrNuser, string isnewpage, string issubmitsign, string isneedsignatrue,
                            string txtOtherTextName)
    {
        TextOperation tp = new TextOperation(cm);
       return tp.InsertText(txtName, txtNumber, cboEditorSelectIndex, fahterId,
                            cboBookAttributeSelectedIndex, mark, sid, signatrue, cboTimeTitle,
                            fromname, cboDoctorOrNuser, isnewpage, issubmitsign, isneedsignatrue,
                            txtOtherTextName);
    }

    public int UpdateText(string txtName, string txtNumber, string cboEditorSelectedIndex, string fahterId, string cboBookAttributeSelectedIndex,
                         string mark, string sid, string signatrue, string cboTimeTitle, string fromname, string cboDoctorOrNuser,
                         string isnewpage, string issubmitsign, string isneedsignatrue, string txtOtherTextName, string selectClasstextId)
    {
        TextOperation tp = new TextOperation(cm);
        return tp.UpdateText(txtName, txtNumber, cboEditorSelectedIndex, fahterId, cboBookAttributeSelectedIndex,
                         mark, sid, signatrue, cboTimeTitle, fromname, cboDoctorOrNuser,
                         isnewpage, issubmitsign, isneedsignatrue, txtOtherTextName, selectClasstextId);
    }

    #endregion

    #region  帐号操作
    public Class_Account GetLoginCurrentAccout(string account, string password)
    {
        Login login = new Login(cm);
        return login.GetLoginCurrentAccout(account,password);
    }

    public bool IsIntimeSpan(string roleid)
    {
        Login login = new Login(cm);
        return login.IsIntimeSpan(roleid);
    }
        
    public Class_Permission[] GetPermissions()
    {
        Login login = new Login(cm);
        return login.GetPermissions();
    }

    public void GetCurrentRolePermissions(ref Class_Role CurrentSelectRole)
    {
        Login login = new Login(cm);
        login.GetCurrentRolePermissions(ref CurrentSelectRole);
    }
    #endregion

    #region 病人操作
    public DataSet GetInptientByDoctorCode(string sick_doctor_name)
    {
        InpatientsOperation inpat = new InpatientsOperation(cm);
        return inpat.GetInptientByDoctorCode(sick_doctor_name);
    }

    public DataSet GetInptientByStr(string patient_name)
    {
        InpatientsOperation inpat = new InpatientsOperation(cm);
        return inpat.GetInptientByStr(patient_name,"");
    }


    public DataSet GetInptientBySectionCode(string section_id)
    {
        InpatientsOperation inpat = new InpatientsOperation(cm);
        return inpat.GetInptientBySectionCode(section_id);
    }

    public InPatientInfo InitPatient(string patientid)
    {
        InpatientsOperation inpat = new InpatientsOperation(cm);
        return inpat.InitPatient(patientid);
    }

    public void GetAgeByBirthDayInfo(string birthday,ref int year, ref int month, ref int day)
    {
        InpatientsOperation inpat = new InpatientsOperation(cm);        
        inpat.GetAgeByBirthday(Convert.ToDateTime(birthday), Dbcom.GetSystemTime(),ref year,ref month,ref day);
    }

    public int PatientInSectionsArea(InPatientInfo inpo, string Account_id)
    {
        InpatientsOperation inpat = new InpatientsOperation(cm);
        return inpat.PatientInSectionsArea(inpo, Account_id);        
    }

    public DataSet GetSection(string sid, string said)
    {
        InpatientsOperation inpat = new InpatientsOperation(cm);
        return inpat.GetSection(sid, said);
    }
    public DataSet GetSickArea(string sid, string said)
    {
        InpatientsOperation inpat = new InpatientsOperation(cm);
        return inpat.GetSickArea(sid, said);
    }
    public DataSet GetEmptyBed(string sid, string said)
    {
        InpatientsOperation inpat = new InpatientsOperation(cm);
        return inpat.GetEmptyBed(sid,said);
    }
    public DataSet GetDoctor(string sid)
    {
        InpatientsOperation inpat = new InpatientsOperation(cm);
        return inpat.GetDoctor(sid);
    }

    public int Test2(int t1, int t2)
    {
        InpatientsOperation inpat = new InpatientsOperation(cm);
        return inpat.Test2(t1,t2);
    }

    public DataSet GetTextTest()
    {
        InpatientsOperation inpat = new InpatientsOperation(cm);
        return inpat.GetTextTest();
    }
    #endregion

    #region 模版管理
    /// <summary>
    /// 获取默认模版
    /// </summary>
    /// <param name="textId"></param>
    /// <returns></returns>
    public string GetDefaultTemp(string textId)
    {
        TemplateOperation tp = new TemplateOperation(cm);
        return tp.GetDefaultTemp(textId);
    }

    /// <summary>
    /// 根据ID获取模版
    /// </summary>
    /// <param name="tid"></param>
    /// <returns></returns>
    public string GetTemplateByid(string tid)
    {
        TemplateOperation tp = new TemplateOperation(cm);
        return tp.GetTemplateByid(tid);
    }


    public UcTreeNode ReflashTemplateBookTree()
    {
        TemplateOperation tp = new TemplateOperation(cm);
        return tp.ReflashTemplateBookTree();
    }

    public UcTreeNode ReflashTemplateTrvBook(string msg)
    {
        TemplateOperation tp = new TemplateOperation(cm);
        return tp.ReflashTemplateTrvBook(msg);
    }

    public UcTreeNode ReflashTemplateTrvBookByCheckType(string chkDocType, string rdoPersonal, string rdoSection, string rdoHospital,
       string rdoGroup, string txtDocName, string chkAllDefault, string chkAll, string chkSectionDefault, string chkSection, string chkGroupDefault,
       string chkGroup, string chkPerson)
    {
        TemplateOperation tp = new TemplateOperation(cm);
        return tp.ReflashTemplateTrvBookByCheckType( chkDocType,  rdoPersonal,  rdoSection,  rdoHospital,
        rdoGroup,  txtDocName,  chkAllDefault,  chkAll,  chkSectionDefault,  chkSection,  chkGroupDefault,
        chkGroup,  chkPerson);
    }


   public string GetNodeColor(Class_Patients templates)
    {
        TemplateOperation tp = new TemplateOperation(cm);
        return tp.GetNodeColor(templates);
    }

    public int AddNewTemplate(string sick_Id, string agestyle, string ages,
        string TName, string Shortcut, string TempPlate_Level, string Sex, string SickArea_ID,
        string Creator_ID, string Create_Time, string Updater_ID, string Update_Time,
        string Verify_ID1, string Verify_Time1,
        string Verify_ID2, string Verify_Time2,
        string Verify_Sign, string Section_ID,
        string ISDEFAULT, string TextKind, string Role_type, string xmldocstr)
    {
        TemplateOperation tp = new TemplateOperation(cm);
        return tp.AddNewTemplate( sick_Id,  agestyle,  ages,
         TName,  Shortcut,  TempPlate_Level,  Sex,  SickArea_ID,
         Creator_ID,  Create_Time,  Updater_ID,  Update_Time,
         Verify_ID1,  Verify_Time1,
         Verify_ID2,  Verify_Time2,
         Verify_Sign,  Section_ID,
         ISDEFAULT,  TextKind,  Role_type,  xmldocstr);
    }

    public int UpdateTemplate(string current_id, string content)
    {
        TemplateOperation tp = new TemplateOperation(cm);
        return tp.UpdateTemplate(current_id, content);
    }


    /// <summary>
    /// 
    /// </summary>
    /// <param name="msg"></param>
    /// <param name="GStyle"></param>
    /// <param name="Kindtid"></param>
    /// <param name="section_id"></param>
    /// <returns></returns>
    public DataSet GetTemplateByCondition(string msg, string GStyle, string Kindtid, string section_id)
    {
        TemplateOperation tp = new TemplateOperation(cm);
        return tp.GetTemplateByCondition( msg,  GStyle,  Kindtid,  section_id);
    }

    public int DeleteTemplate(string tid)
    {
        TemplateOperation tp = new TemplateOperation(cm);
        return tp.DeleteTemplate(tid);
    }


    public DataSet GetTemplateChildNodesOrder(string parentid)
    {
        TemplateOperation tp = new TemplateOperation(cm);
        return GetTemplateChildNodesOrder(parentid);
    }

    public int SetTemplateChildNodesOrder(string autotype, List<string> conditons)
    {
        TemplateOperation tp = new TemplateOperation(cm);
        return SetTemplateChildNodesOrder(autotype, conditons);
    }
    #endregion

    #region 知识库维护
    public DataSet GetDataSetTABLE_F()
    {
        KnowledgeOperation Knowledge = new KnowledgeOperation(cm);
        return Knowledge.GetDataSetTABLE_F();
    }
    public DataSet GetDataSetTABLE_E(string id)
    {
        KnowledgeOperation Knowledge = new KnowledgeOperation(cm);
        return Knowledge.GetDataSetTABLE_E(id);
    }

    public int DeleteTable_F(string ID, string parentId)
    {
        KnowledgeOperation Knowledge = new KnowledgeOperation(cm);
        return Knowledge.DeleteTable_F(ID, parentId);
    }

    public DataSet GetObjectDataById(string ObjectId)
    {
        KnowledgeOperation Knowledge = new KnowledgeOperation(cm);
        return Knowledge.GetObjectDataById(ObjectId);
    }

    public int SaveSimpleElement(string SaveType, string txtNum, string txtName, string txtCode, string selnodeText, string selnodeTag,ref string id)
    {
        KnowledgeOperation Knowledge = new KnowledgeOperation(cm);
        return Knowledge.SaveSimpleElement( SaveType,  txtNum,  txtName,  txtCode,  selnodeText,  selnodeTag,ref id);
    }

    public int SaveComplexElement(string SaveType, string tvDirectorySelectedText, string tvListSelectedNodeName, 
        string txtComplexName, string tvDirectorySelectedTag, string tvListSelectedNodeTag, string tvListCount, string DocXML,
        ref string id, ref string evalueCode)
    {
        KnowledgeOperation Knowledge = new KnowledgeOperation(cm);
        return Knowledge.SaveComplexElement(SaveType, tvDirectorySelectedText, tvListSelectedNodeName, 
            txtComplexName, tvDirectorySelectedTag, tvListSelectedNodeTag, tvListCount, DocXML,ref id, ref evalueCode);
    }

    public int ElementDelete(string delType, string id, string objectid)
    {
        KnowledgeOperation Knowledge = new KnowledgeOperation(cm);
        return Knowledge.ElementDelete(delType,id,objectid);
    }
    #endregion

    #region 基础项操作
    public DataSet GetAllSection()
    {
        DatabaseOperation dp = new DatabaseOperation(cm);
        return dp.GetAllSection();
    }

    public List<FixTypeObject> GetFixTypeObjects()
    {
        DatabaseOperation dp = new DatabaseOperation(cm);
        return dp.GetFixTypeObjects();
    }

    public DataSet GetDataSetByType(string type)
    {
        DatabaseOperation dp = new DatabaseOperation(cm);
        return dp.GetDataSetByType(type);
    }

    public DataSet GetCitysByProviceId(string provinceId)
    {
        DatabaseOperation dp = new DatabaseOperation(cm);
        return dp.GetCitysByProviceId(provinceId);
    }
    #endregion
}
